﻿using AutoMapper;
using B.S.DataBase.MyProject.Domain.RBAC;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyWrite.API.Appicant.Command.Menus;
using MediatR;

namespace B.S.DataBase.MyWrite.API.Appicant.CommandHandler.Menus
{
    public class InsertRoleMenuHandler : IRequestHandler<InsertRoleMenu, APIResult<object>>
    {
        private readonly IBaseRepository<RoleMenu> _roleMenu;
        private readonly IMapper mapper;

        public InsertRoleMenuHandler(IBaseRepository<RoleMenu> roleMenu, IMapper mapper)
        {
            _roleMenu = roleMenu;
            this.mapper = mapper;
        }

        public async Task<APIResult<object>> Handle(InsertRoleMenu request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
            result.Code=APIEnum.添加成功;
            result.Msg = APIEnum.添加成功.ToString();
            var entity=mapper.Map<RoleMenu>(request);
            await _roleMenu.Add(entity);
            return await Task.FromResult(result);
        }
    }
}
